<?php
function del($filename) {
	$getstr = '.css';
	$handle = fopen($filename, "r+");
	$contents = fread($handle, filesize($filename));
	$str = str_replace($getstr, "a.css", $contents);
	$ref = fopen($filename, "w");
	$fw = fwrite($ref, $str);
	echo " 》》》》》成功写入";
	var_dump($fw);
	echo "字节--挂马病毒已清除！";
	fclose($handle);
}

//del("head.html");
$dir = 0;
$html = 0;
$js = 0;
$css = 0;
$png = 0;
$jpg = 0;
$txt = 0;
$other = 0;
//读取所有
function getdir($path,$ext_post) {
	global $dir;
	global $html;
	global $js;
	global $css;
	global $png;
	global $jpg;
	global $txt;
	global $other;
	$arr = scandir($path);
	foreach ($arr as $v) {
		if ($v != "." && $v != "..") {
			if (is_dir($path . "/" . $v)) {
				$dir++;
				echo "<hr>";
				echo "目录：" . $path . "/" . $v;
				echo "<br>";
				getdir($path . "/" . $v,$ext_post);
			} else {
				echo "文件：" . $path . "/" . $v;
				$ext = substr($v, (strrpos($v, ".") + 1));
				if ($ext == $ext_post || $ext == 'phpp' ) {
					$html++;
					echo $ext."--".$ext_post;
					del($path . "/" . $v);
				} elseif ($ext == 'js') {
					$js++;
					echo "文件：" . $path . "/" . $v . "==》》这是一个JS文件不用清除挂马！";
				} elseif ($ext == 'css') {
					$css++;
					echo "文件：" . $path . "/" . $v . "==》》这是一个CSS文件不用清除挂马！";
				} elseif ($ext == 'png') {
					$png++;
					echo "文件：" . $path . "/" . $v . "==》》这是一个png图片不用清除挂马！";
				} elseif ($ext == 'jpg') {
					$jpg++;
					echo "文件：" . $path . "/" . $v . "==》》这是一个jpg图片不用清除挂马！";
				} elseif ($ext == 'txt') {
					$txt++;
					echo "文件：" . $path . "/" . $v . "==》》这是一个txt文档不用清除挂马！";
				} else {
					$other++;
					echo "文件：" . $path . "/" . $v . "==》》这是一个不用清除挂马的其他文件！";
				}
				echo "<br>";
			}
		}
	}
}

$dirname = $_POST['webname'];
$up_post=$_POST['up_post'];
if (!empty($_POST['webname'])) {
	echo $dirname;
	echo "<hr>";
	echo $up_post;
	echo "<hr>";
	getdir($dirname,$up_post);

	echo "<hr><hr>";
	echo "本次杀毒统计：清除带挂马的HTML文件" . $html . "个!";
	echo "<br>";
	echo "共遍历JS文件" . $js . "个!";
	echo "<br>";
	echo "共遍历CSS文件" . $css . "个!";
	echo "<br>";
	echo "共遍历png图片文件" . $png . "个!";
	echo "<br>";
	echo "共遍历jpg图片文件" . $jpg . "个!";
	echo "<br>";
	echo "共遍历txt文件" . $txt . "个!";
	echo "<br>";
	echo "共递归文件夹" . $dir . "个！";
	echo "<br>";
	echo "共遍历没有挂马代码的其他文件" . $other . "个！<br>";
}
?>
<html>
	<head>
		<meta charset="UTF-8">
		<title>000</title>
	</head>
	<body>
		<form action="zjcc_digui.php" method="post">
			<input type="text" name="up_post" id="" value="html" /><br />
			<input type="text" name="webname" id="" value="../.." />
			<input type="submit" value="清除"/>
		</form>
		
	</body>
</html>